package view;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPanel;

import controller.Controller;

import model.LED;

/**
 * LED megjelenítéséért felelős osztály
 * JPanel és MouseListener leszármazás és implementálás a kattinthatóságért
 * @author radioactivebee
 *
 */
public class LEDView extends JPanel implements Paintable, MouseListener, ModelProvider {

	private static final long serialVersionUID = 1L;
	private int x;
	private int y;
	private LED led;
	public InputView inputView;
	
	public LEDView(int x, int y, LED led) {
		super();
		this.x = x;
		this.y = y;
		this.led = led;
		setBounds(this.x, this.y, 25, 25);
		addMouseListener(this);
		this.inputView = new InputView(x+12, y+12, led.getInput(), led);
	}
	
	@Override
	public void mouseClicked(MouseEvent e){
		if(Controller.verbose){
			System.out.println("ledview mouse listener invoked");
		}
		Controller.getInstance().inputClicked(inputView);
		Controller.getInstance().blockClicked(this);
	}
	@Override
	public void paint(Graphics g) {
		if (led.getInput().getState().equals(false)){
			g.setColor(Color.WHITE);
		} else {
			g.setColor(Color.RED);			
		}	
		if(InputView.darken){
			g.setColor(g.getColor().darker());
		}
		g.fillOval(x, y, 25, 25);
		
		g.setColor(Color.BLACK);
		g.drawOval(x, y, 25, 25);
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public LED getModel(){
		return led;
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
	}

	@Override
	public void mousePressed(MouseEvent arg0) {	
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
	}
}
